use async_trait::async_trait;
use uuid::Uuid;


#[derive(Debug, thiserror::Error)]
pub enum TaskError {
    #[error("{0}")]
    Custom(String),
}

#[async_trait]
pub trait Runnable {
    async fn run(&self) -> Result<(), TaskError>;
}

#[async_trait]
pub trait Stopable {
    async fn stop(&self) -> Result<(), TaskError>;
}

pub trait Task: Runnable + Stopable + Send + Sync {
    fn type_name(&self) -> &'static str;
    fn serialize(&self) -> Result<String, TaskError>;
}

pub struct TaskHandler {
    pub id: String,
}

impl TaskHandler {
    pub fn new() -> Self {
        Self {
            id: Uuid::new_v4().to_string(),
        }
    }
}
